package com.wngbms.feigndemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
        // 如果设置的太短 服务端没有返回 会超时异常
        configurer.setDefaultTimeout(50 * 1000L);
        configurer.setTaskExecutor(threadPoolTaskExecutor());
    }

    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor t = new ThreadPoolTaskExecutor();
        t.setCorePoolSize(10);
        t.setMaxPoolSize(10);

        t.setThreadNamePrefix("mvc-async-thread");
        t.setQueueCapacity(1024);
        t.setAllowCoreThreadTimeOut(true);
        t.setKeepAliveSeconds(30);

        return t;
    }

}
